version 12.1
clear all
set more off
cap log close
log using tabdata5-3empcen.log, replace text
set linesize 255

*****************************************************
* EMPLOYMENT COUNTS BY INDUSTRY BY YEAR
*****************************************************
/*
PURPOSE: combine census and enterprise employment counts by year x industry

CHANGES:
- 8/27: focus on census 95 and 08 employment counts.
*/
*****************************************************
* Date created: 8/16/2013 by Ying Chen
* Date updated: 8/27/2013
*****************************************************
* Files in:
global cnsct2 "..\..\data\empcensus\generated\cns_emp_count_newind.dta"
global corr "..\..\data\correspondence_tables\generated\correspondence_82_10.dta"
* Files out:
global out2 "..\..\data\empcensus\generated\emp_count_newind.dta"
*****************************************************
******************************
* unit_code_common and cc05 crosswalk
******************************
use $corr, clear
drop if unit_code_common==.
contract unit_code_common city05 cp90
rename city05 cc05
drop _freq
tempfile corr
save `corr'

* Updated on 8/27. 
use $cnsct2, clear
merge m:1 unit_code_common using `corr'
drop _me
tempfile main
save `main'

* Pref level
use `main', clear
collapse (sum) unit_emp food_emp trad_emp txtlaprl_emp plstc_emp nonmtl_emp metals_emp metal_emp metalpdct_emp machinery_emp cptNinst_emp ht_emp nonht_emp aprl_emp eduspt_emp geq_emp seq_emp trans_emp ptran_emp eeq_emp comm_emp inst_emp art_emp lghttrad_emp hvytrad_emp plstcNrbbr_emp allhvy_emp allmdm_emp, by(year cc05)
reshape wide unit_emp food_emp trad_emp txtlaprl_emp plstc_emp nonmtl_emp metals_emp metal_emp metalpdct_emp machinery_emp cptNinst_emp ht_emp nonht_emp aprl_emp eduspt_emp geq_emp seq_emp trans_emp ptran_emp eeq_emp comm_emp inst_emp art_emp lghttrad_emp hvytrad_emp plstcNrbbr_emp allhvy_emp allmdm_emp, i(cc05) j(year)
rename *_emp???? *_emp????_pref
tempfile p
save `p'

* CP10 level
use `main', clear
keep if cp90==1
collapse (sum) unit_emp food_emp trad_emp txtlaprl_emp plstc_emp nonmtl_emp metals_emp metal_emp metalpdct_emp machinery_emp cptNinst_emp ht_emp nonht_emp aprl_emp eduspt_emp geq_emp seq_emp trans_emp ptran_emp eeq_emp comm_emp inst_emp art_emp lghttrad_emp hvytrad_emp plstcNrbbr_emp allhvy_emp allmdm_emp, by(year cc05)
reshape wide unit_emp food_emp trad_emp txtlaprl_emp plstc_emp nonmtl_emp metals_emp metal_emp metalpdct_emp machinery_emp cptNinst_emp ht_emp nonht_emp aprl_emp eduspt_emp geq_emp seq_emp trans_emp ptran_emp eeq_emp comm_emp inst_emp art_emp lghttrad_emp hvytrad_emp plstcNrbbr_emp allhvy_emp allmdm_emp, i(cc05) j(year)
rename *_emp???? *_emp????_cp90
tempfile cp
save `cp'

merge 1:1 cc05 using `p', nogen

sort cc05
save $out2, replace

log close

version 11
